package cn.xuewenbao.edu.mapper;

import cn.xuewenbao.edu.entity.Article;
import cn.xuewenbao.edu.entity.vo.ArticleInfoVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 文章表 Mapper 接口
 * </p>
 *
 * @author mafayu
 * @since 2021-03-22
 */
@Mapper
public interface ArticleMapper extends BaseMapper<Article> {

    @Select("SELECT a.id, a.user_id, m.username userName, m.avatar, a.title, a.cover, a.content, a.view_count, a.gmt_create, (SELECT COUNT(1) FROM follow f WHERE f.user_id = #{userId} and f.followed_user_id = a.user_id)>0 AS isFollow, (SELECT COUNT(1) FROM like_content l WHERE l.user_id = #{userId} and l.content_id = a.id and l.column_type = #{columnType} )>0 AS isLike\n" +
            "FROM article a\n" +
            "LEFT JOIN member m ON a.user_id = m.id\n" +
            "WHERE a.id = #{articleId}")
    ArticleInfoVo selectArticleInfoByArticleIdAndUserId(String articleId, String userId, String columnType);
}
